﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using vite_entity.Entities;

namespace vite_entity.EntityTypeConfig
{
    public class SysUserRole_TypeConfig : IEntityTypeConfiguration<SysUserRole>
    {
        public void Configure(EntityTypeBuilder<SysUserRole> entity)
        {
            entity.HasKey(e => new { e.UserId, e.RoleId })
                .HasName("PRIMARY")
                .HasAnnotation("MySql:IndexPrefixLength", new[] { 0, 0 });

            entity
                .ToTable("sys_user_role", tb => tb.HasComment("用户和角色关联表"))
                .UseCollation("utf8mb4_general_ci");

            entity.HasIndex(e => new { e.UserId, e.RoleId }, "uk_userid_roleid").IsUnique();

            entity.Property(e => e.UserId)
                .HasComment("用户ID")
                .HasColumnName("user_id");
            entity.Property(e => e.RoleId)
                .HasComment("角色ID")
                .HasColumnName("role_id");
        }
    }
}
